﻿using System;
using System.Configuration;
using System.Collections.ObjectModel;

namespace ADI.Security.Authorization
{
    public class ADISSOLocationCollection : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new ADISSOLocation();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((ADISSOLocation)element).path;
        }
    }

    public class ADISSOLocations : ConfigurationSection
    {
        [ConfigurationProperty("Locations", IsDefaultCollection = true)]
        [ConfigurationCollection(typeof(ADISSOLocation), AddItemName = "ADISSOLocation")]
        public ADISSOLocationCollection Locations
        {
            get { return base["Locations"] as ADISSOLocationCollection; }
            set { base["Locations"] = value; }
        }
    }

    public class ADISSOLocation : ConfigurationElement
    {
        [ConfigurationProperty("path", IsKey = true, DefaultValue = "", IsRequired = true)]
        public string path
        {
            get { return this["path"].ToString(); }
        }

        [ConfigurationProperty("allow", IsRequired = true)]
        public AllowElement allow
        {
            get { return (AllowElement)this["allow"]; }
            set { this["allow"] = value; }
        }

        [ConfigurationProperty("deny", IsRequired = false)]
        public DenyElement deny
        {
            get { return (DenyElement)this["deny"]; }
            set { this["deny"] = value; }
        }
    }

    public class AllowElement : ConfigurationElement
    {
        [ConfigurationProperty("roles", IsRequired = true)]
        public string roles
        {
            get { return this["roles"].ToString(); }
        }

        [ConfigurationProperty("requireManager", IsRequired = false)]
        public string requireManager
        {
            get { return this["requireManager"].ToString(); }
        }
    }

    public class DenyElement : ConfigurationElement
    {
        [ConfigurationProperty("roles", IsRequired = true)]
        public string roles
        {
            get { return this["roles"].ToString(); }
        }
    }
}

